var apiUrl=contextPath+"/customer/follow/getlist";
var listVue=new Vue({
  el: '#followList',
  data: {
	  params:{
		  pageSize:10,
		  pageNum:1,
		  projectId:'',
		  followModes:''
	  },
  	  ppList:[],
  	  projectList:[],
  	  userList:[],
  	  picList:[],
  	  radioList:[],
  	  selectcontents:"",
  	  content:"",
  	  permitBtn:'',
  	  permission:{
 		  downLoad:false,
 		  del:false,
 	  }
  },
  mounted:function(){
	  //初始化项目
	  this.initProject();
  },
  methods: {
     getList:function() {
    	var _self = this;
    	if(_self.params.projectId==""){
    		layer.tips('项目必选', '#queryProjectId', {
    			  tips: [2, '#FF5722'],
    			  time: 2000
    		});
    		return;
    	}
    	var loadIndex = layer.load(0, {shade: false});
    	_self.params.followTimeBefore=$("#followTimeBefore").val();
    	_self.params.followTimeAfter=$("#followTimeAfter").val();
    	_self.params.nextFollowTimeBefore=$("#nextFollowTimeBefore").val();
    	_self.params.nextFollowTimeAfter=$("#nextFollowTimeAfter").val();
     	$.ajax({
    		type:'post',
            url: apiUrl,
    	    data:_self.params,
    	    dataType:'json',
    	    success: function(res){
    	    	layer.close(loadIndex);
    	    	if(res.res=="1"){
    	    		var rows=res.obj.rows;
        	    	_self.ppList=rows;
        	    	//初始化分页
                	var pages=res.obj.totalPages;
    	        	var current=res.obj.pageNumber;
            	    laypage({
            		  cont: $('#pagination'), //容器。值支持id名、原生dom对象，jquery对象,
            		  pages: pages, //总页数
            		  curr:current,
            		  skip: true, //是否开启跳页
            		  skin: 'molv',
            		  groups: 3, //连续显示分页数
            		  jump: function(obj,first){
            			  if(!first){
            				  _self.params.pageNum=obj.curr;
            				  _self.getList();
            			  }
            		  }
            		});
            	    
    	    	}else{
    	    		layer.close(loadIndex);
    	    		layer.alert(res.resMsg);
    	    	}
    	    	
    	    },
    	    error:function(res){
    	    	
    	    }
    	});   
     },
     initProject:function(){
    	    var _self = this;
    	    var url=contextPath+"/customer/follow/getIndex";
    		$.ajax({
    			type: 'post',
    	        url: url,
    		    data: {
    		    	menu:'menu_0006_0002'
    		    },
    		    dataType:'json',
    		    success: function(res){
    		    	if(res.res==1){
    		    		//按钮权限
    		    		_self.permitBtn =res.obj.permitBtn;
    		    		//项目id
	 		    		_self.params.projectId=res.obj.projectId;
    		    		//项目列表
    		    		_self.projectList=res.obj.projects;
	 		    		_self.initUserIdStore();
	 		    		_self.getList();
	 		    		//初始化权限
	 		    		_self.initPermission();
    		    	}else{
    		    		window.location.href=contextPath+res.resMsg;
    		    	}
    		    }
    		});
     },
     initUserIdStore:function(){
    	 	var _self = this;
    	 	var projectId = _self.params.projectId;
    	 	if(projectId){
    	 		var url=contextPath+"/customer/customer/userByProjectIdForGroup";
    	 		$.ajax({
    	 			type: 'post',
    	 	        url: url,
    	 		    data: {
    	 		    	projectId:projectId
    	 		    },
    	 		    dataType:'json',
    	 		    success: function(res){
    	 		    	_self.userList=res;
    	 		    }
    	 		});
    	 	}else{
    	 		_self.userList=null;
    	 	}
     },
     initPermission(){
     	var _self = this;
     	var objList=JSON.parse(_self.permitBtn);
  		var del="customer:follow:delete";
  		var downLoad="customer:follow:downLoad";
  		for(ob in objList){
  			var permission=objList[ob];
  			if(permission==del){
  				_self.permission.del=true;
  			}else if(permission==downLoad){
  				_self.permission.downLoad=true;
  			}
  		}
     },
     clearForm:function(){
//    	 this.params.projectId='';
//    	 this.ppList=[];
//    	 this.projectList=[];
//    	 this.userList=[];
    	 this.picList=[];
    	 this.radioList=[];
    	 this.params.followModes="";
    	 this.params.userCode="";
    	 $("input[name='followModes']").each(
    		function(){
    			$(this).get(0).checked=false;
		  });
    	 this.params.followTimeBefore="";
    	 this.params.followTimeAfter="";
    	 this.params.nextFollowTimeBefore="";
    	 this.params.nextFollowTimeAfter="";
     	 $("#followTimeBefore").val(null);
     	 $("#followTimeAfter").val(null);
     	 $("#nextFollowTimeBefore").val(null);
     	 $("#nextFollowTimeAfter").val(null);
     	 this.params.pageNum=1;
     	 this.params.pageSize=10;
     },
     genjin:function(id,type){
    	 var _self = this;
    	 var url=contextPath+"/customer/customer/getImageList";
	  		$.ajax({
	  			type: 'post',
	  	        url: url,
	  		    data: {
	  		    	objectId:id,
	  		    	imgType:4
	  		    },
	  		    dataType:'json',
	  		    success: function(res){
	  		    	if(type==2){
	  		    		_self.picList=res;
	  		    	}else if(type==3){
	  		    		_self.radioList=res;
	  		    	}
	  		    }
	  		});
     },
     selectContent:function(value,type){
    	 var _self = this;
    	 if(type==1){
    		 _self.content= "跟进内容";
    	 }else if(type==2){
    		 _self.content= "提醒内容";
    	 }
    	 _self.selectcontents=value;
     },
     del:function(id){
    	 var _self = this;
    	 layer.confirm('确定删除?', function(){ 
    		 var url=contextPath+"/customer/follow/delete";
 	  		 $.ajax({
 	  			type: 'post',
 	  	        url: url,
 	  		    data: {
 	  		    	id:id
 	  		    },
 	  		    dataType:'json',
 	  		    success: function(res){
 	  		    	if(res.res==1){
 	  		    		layer.msg("删除成功");
 	  		    		_self.getList();
 	  		    	}else{
 	  		    		layer.alert("删除失败");
 	  		    	}
 	  		    }
 	  		});
    	});
     },
     selectModes:function(){
    	 var ck="";
    	 var _self = this;
    	 $("input[name='followModes']").each(
		   function(){
			   if($(this).get(0).checked){
				  ck += $(this).get(0).value+','
			   }
		  });
    	 _self.params.followModes=ck;
     }
  }
})

Vue.filter('mode', function (value) {
	 if (value == 1) {
         return '来电';
     } else if (value == 2) {
         return '来访';
     }else if (value == 3) {
         return '信息';
     }else if (value == 4) {
         return '去电';
     }else if (value == 5) {
         return '拜访';
     }else if (value == 6) {
         return '系统生成';
     }else if (value == 7) {
         return '微信';
     }
     return val;
});
Vue.filter('content', function (value,type) {
	 if (type == 2) {
        return '预览图片';
    } else if (type == 3) {
        return '播放语音';
    }
    return value;
});
Vue.filter('callStatus', function (value,recordUrl) {
	 if (value == 0) {
       return '未取话单';
   } else if (value == 1) {
       return '听录音';
   } else if (value == 2) {
       return '未接通';
   }
   return value;
});


